package com.yunxi.controller.sat;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sat.pojo.SatTestDriveCancelVO;
import com.yunxi.sat.pojo.SatTestDriveCompletelVO;
import com.yunxi.sat.pojo.SatTestDriveVO;
import com.yunxi.sat.service.SatTestDriveDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 试乘试驾表 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-07-31
 */
@RestController
@RequestMapping("/admin/satTestDrive")
@Api(tags = "sat:testDrive", description = "试乘试驾表接口")
public class SatTestDriveController {
    private static final Logger logger = LoggerFactory.getLogger(SatTestDriveController.class);

    @Autowired
    SatTestDriveDubboService satTestDriveDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(SatTestDriveVO satTestDriveVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(satTestDriveDubboService.findPageByVO(satTestDriveVO, pageNum, pageSize,loginInfo));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public ApiResult list(SatTestDriveVO satTestDriveVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(satTestDriveDubboService.listByVo(satTestDriveVO,loginInfo));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    @ApiImplicitParam(paramType="query", name = "driveId", value = "主键id", required = true, dataType = "String")
    public ApiResult load(String driveId) throws Exception {
        return ResponseUtil.ok(satTestDriveDubboService.getInfoById(driveId));
    }

    @GetMapping("/testDriveInfo")
    @ApiOperation(value = "通过客户编号查询试驾信息")
    @ApiImplicitParam(paramType="query", name = "customerNo", value = "客户编号", required = true, dataType = "String")
    public ApiResult testDriveInfo(String customerNo) throws Exception {
        return ResponseUtil.ok(satTestDriveDubboService.testDriveInfo(customerNo));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody SatTestDriveVO satTestDriveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        String driveId = satTestDriveDubboService.saveOrUpdate(satTestDriveVO, loginInfo);
        return ResponseUtil.ok(driveId);
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<SatTestDriveVO> satTestDriveVOList) throws Exception {
        satTestDriveDubboService.removeByListVo(satTestDriveVOList);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/aggreeMent")
    @ApiOperation(value = "查询试驾协议")
    public ApiResult load(@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(satTestDriveDubboService.aggreeMent(loginInfo.getPartnerCode()));
    }

    @PostMapping("/cancelTestDrive")
    @ApiOperation(value = "取消试驾")
    public ApiResult cancelTestDrive(@RequestBody SatTestDriveCancelVO satTestDriveCancelVO) throws Exception {
        satTestDriveDubboService.cancelTestDrive(satTestDriveCancelVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/begin")
    @ApiOperation(value = "开始试驾")
    public ApiResult begin(@RequestBody SatTestDriveCompletelVO satTestDriveCompletelVO) throws Exception {
        satTestDriveDubboService.begin(satTestDriveCompletelVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/complete")
    @ApiOperation(value = "完成试驾")
    public ApiResult complete(@RequestBody SatTestDriveCompletelVO satTestDriveCompletelVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        satTestDriveDubboService.complete(satTestDriveCompletelVO,loginInfo.getRoleCode());
        return ResponseUtil.ok("success");
    }

    @GetMapping("/allList")
    @ApiOperation(value = "本月新增试驾")
    public ApiResult allList(SatTestDriveCompletelVO satTestDriveCompletelVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(satTestDriveDubboService.allList(satTestDriveCompletelVO,loginInfo));
    }

    @GetMapping("/testDriveDate")
    @ApiOperation(value = "查询试驾专家待试驾时间列表")
    @ApiImplicitParam(paramType="query", name = "testDriveExpert", value = "试驾专家编号", required = true, dataType = "String")
    public ApiResult testDriveDate(String testDriveExpert, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(satTestDriveDubboService.testDriveDate(testDriveExpert,loginInfo.getPartnerCode()));
    }

    @PostMapping("/editDriveTime")
    @ApiOperation(value = "更改计划试驾时间")
    public ApiResult editDriveTime(@RequestBody SatTestDriveCancelVO satTestDriveCancelVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        satTestDriveDubboService.editDriveTime(satTestDriveCancelVO);
        return ResponseUtil.ok("success");
    }

}
